<?php

abstract class CModule extends CComponent
{
	
	
	public function preinit()
	{
		
	}
	
	public function setComponents($components,$merge=true)
	{
		foreach($components as $id=>$component)
		{
			if($component instanceof IApplicationComponent)
			{
				$this->setComponent($id,$component);
			}
			else if(isset($this->_componentConfig[$id]) && $merge)
			{
				$this->_componentConfig[$id]=CMap::mergeArray($this->_componentConfig[$id],$component);
			}
			else 
			{
				$this->_componentConfig[$id]=$component;
			}
		}
	}
	
	public function setComponent($id,$component)
	{
		if($component===null)
		{
			unset($this->_components[$id]);
		}
		else
		{
			$this->_components[id]=$component;
			if(!$component->getIsInitialized())
			{
				$component->init();
			}
		}
		
	}
	
	
}